#ifndef DATA
#define DATA 1

#include <math.h>
#include <string.h>
#include <iostream.h>
#include <fstream.h>
#include <stdlib.h>

#include "TROOT.h"
#include "TSystem.h"
#include "TTree.h"
#include "TObject.h"
#include "TVector3.h"

#include "G4RunManager.hh"
#include "G4UImanager.hh"
#include "G4UIterminal.hh"
#include "G4UItcsh.hh"
#include "G4ThreeVector.hh"
#include "G4LorentzVector.hh"
#include "G4Transform3D.hh"
#include "G4AffineTransform.hh"
#include "globals.hh"

class Data;

#include "Settings.hh"
#include "MiniBallHistoManager.hh"
#include "MiniBallTripleDetector.hh"

#include "Element.hh"
#include "Material.hh"
#include "Isotopes.hh"

#include "CommandLineInterface.hh"

class Data : public TObject
{
public:
  Data();
  Data(int argc, char* argv[]);
  ~Data();

  int ReadLevels();
  int ReadBetaLevels();
  void CreateBranches(TTree*);
  void run(G4RunManager*);  
  int DetectorType(int HCID);
public:
  //parameters
  Bool_t ISession;             //interactive session
  Bool_t Vis;                  //visualization with OGLS_vis.mac
  G4String Filename;          //name of output file (= test.root)
  Int_t NoE;                  //number of events
  Int_t Tracking;             //tracking
  G4String Settingsfile;          //name of file with settings (= Settings.dat)
  Settings* settings;
  Bool_t TestFlag;            //for testing purposes (can be used to turn certain code parts on or off)
  Double_t BeamWidth;        //width of the beam
  Double_t BeamEnergy;
  Double_t AngleWidth;        //width of the beam
  Element* Projectile;
  Element* Target;
  Element* Recoil;
  Element* Ejectile;
  Material* TargetMaterial;
  Element** ElasticTarget;
  G4String ProjectileName;
  G4String TargetName;
  Double_t TargetRatio;
  Int_t TransferFlagN, TransferFlagP;
  Bool_t CDhit;               //only track if hit in CD
  Bool_t TrackAll;           //track every particle (even if no hit anywhere)
  Double_t ThicknessStepSize;
  Int_t NumberOfThicknessSteps;
  Int_t Reaction;
  Double_t ReactionEnergy;
  Double_t EexEnergy;
  Double_t EjectileEnergy;
  Double_t RecoilEnergy;
  G4String EjectileParticleName;
  G4String RecoilParticleName;
  Double_t CDResolution; //resolution (fwhm) of cd detectors (in keV)
  Double_t BarrelResolution; //resolution (fwhm) of barrel detectors (in keV)
  Double_t TransferCrossSection; //from 0 to 1, 0 means no transfer reactions, 1 only transfer reactions
  Int_t Cut;
  Double_t ThetaCmMin;
  Double_t ThetaCmMax;
  Bool_t WriteAll;
  G4double DetectionEnergy;
  Bool_t CobaltSource;
  Bool_t EuropiumSource;
  Int_t ChamberType;
  Bool_t Gammas;
  Bool_t Efficiency;
  Bool_t Coulex;
  Bool_t IsoGamma;
  Int_t OnePartOnly;
  Int_t GammaCounter[8];
  Int_t VerboseLevel;
  Bool_t IsotropeParticleDistribution;
  Bool_t DeltaE;
  Bool_t Screening;
  Double_t BeamParticles;
  Bool_t RotateMiniball;
  Int_t ExperimentType;
  G4String ScreeningMaterialName;
  Bool_t AlphaSource;
  Bool_t QuadAlphaSource;
  Double_t BetaEnergy;
  Double_t AddBeta;
  Double_t RatioBeta;
  Int_t BackwardFoil;

  Int_t noCarbon;
  Double_t Lifetime;
  Int_t DownScale;

  Int_t BarrelType;
  Int_t CDPad;
  Int_t FirstBarrelHC;
  Int_t BarrelDetectors;
  Int_t Quadrants;

  Int_t NumberOfLevel;
  Double_t* LevelEnergy;
  Double_t* LevelWidth;
  Double_t* FeedingProbability;
  G4String AngularDistributionFile;
  G4String LevelFile;
  G4double* Factor;
  G4double* Exponent;
  G4int* LevelID;
  G4double* LevelSpin;
  G4int* LevelParity;
  G4int* NumberOfDecays;
  G4int** DecayLevel;
  G4double** DecayProbability;
  G4int** DecayType;
  G4double** DecayDelta;

  //betas
  G4String BetaFile;
  Int_t BetaNrOfLevels;
  Double_t* BetaLevelEnergy;
  Double_t* BetaPopulation;


  Bool_t OpticalPotential;
  G4String OpticalPotentialFile;
  G4double OpticalFactor;
  G4double OpticalExponent;

  G4String CommandLine;       //store commandline

  Isotopes* IsotopeTable;
  //variables for histogramming
  Int_t EventNumber;             //event number
  Int_t DetectedEventNumber;     //detected event number
  Double_t ReactionX;            //actual x-position of reaction
  Double_t ReactionY;            //actual y-position of reaction
  Double_t ReactionZ;            //actual z-position of reaction
  Double_t TargetZ;              //actual z-position of reaction in mg/cm2 with 0 = target front
  Double_t Theta_cm;             //cm-angle of particles
  Double_t EjectileTheta;
  Double_t EjectilePhi;
  Double_t RecoilTheta;
  Double_t RecoilPhi;
  Double_t Transfer;

  int HitsInFBarrel;
  int HitsInBBarrel;
  int HitsInFCD;
  int HitsInBCD;
  int HitsInMiniball;

  Bool_t MiniballEndOfEventAction;

  //
  G4String* HCName;       //names of Hitcollections
  Int_t NumberOfHC;        //number of HC's used


  //file-paths
  G4String MassFile;
  G4String ScratchDirectory;
  G4String SimulationDirectory;

  long long EventTime;
};
#endif










